package com.orangecy.rulesubscribe.actuator;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author : orangeCy.奕
 * @Product : 猎豹养成产品源码
 * @Time : 2021/11/14
 * @Desc :
 */
public class ActuatorStrategyContainer implements BeanPostProcessor {

    private final ConcurrentHashMap<String,ActuatorStrategy> strategyMap = new ConcurrentHashMap<>(16);

    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        if(o instanceof ActuatorStrategy) {
            strategyMap.put(((ActuatorStrategy) o).getActuatorType(),(ActuatorStrategy) o);
        }
        return o;
    }

    public ActuatorStrategy getStrategy(String actuatorType) {
        return strategyMap.get(actuatorType);
    }
}